<?php

namespace App\Admin\Controllers;

use App\Models\CrawlerPictuer;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class CrawlerPictuersController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('Index')
            ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('Detail')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('Edit')
            ->description('description')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('Create')
            ->description('description')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CrawlerPictuer);

        $grid->id('Id');
        $grid->origin('Origin');
        $grid->download_count('下载次数')->editable('select', [0 => '0', 1 => '1', 2 => '2', 3 => '3']);//->editable();
        $grid->oss('Oss');
        $grid->crawler('已下载')->editable('select', [0 => '未下载', 1 => '已下载']);
        $grid->column('category.name', '所属分类');
        $grid->pictuer_id('Pictuer id');
        $grid->crawler_article_id('Crawler article id');
        $grid->created_at('添加时间');
        $grid->updated_at('修改时间');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CrawlerPictuer::findOrFail($id));

        $show->id('Id');
        $show->origin('Origin');
        $show->oss('Oss');
        $show->crawler('Crawler');
        $show->category_id('Category id');
        $show->pictuer_id('Pictuer id');
        $show->crawler_article_id('Crawler article id');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new CrawlerPictuer);

        $form->text('origin', 'Origin');
        $form->text('oss', 'Oss');
        // $form->text('download_count','下载次数');
        $form->switch('crawler', 'Crawler');
        $form->number('category_id', 'Category id');
        $form->number('pictuer_id', 'Pictuer id');
        $form->number('crawler_article_id', 'Crawler article id');

        return $form;
    }
}
